package org.hanjell.android.capabilities;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView textField = (TextView) findViewById(R.id.text_field);
        if (hasRootPermission()) {
            textField.setText(R.string.root_ok);
        } else {
            textField.setText(R.string.root_ko);
        }
    }

    public boolean hasRootPermission() {
        boolean rooted = true;
        try {
            File su = new File("/system/bin/su");
            if (su.exists() == false) {
                su = new File("/system/xbin/su");
                if (su.exists() == false) {
                    rooted = false;
                }
            }
        } catch (Exception e) {
            Log.v("AndroidCapabilities",
                    "Error getting the root: " + e.getMessage());
            rooted = false;
        }

        return rooted;
    }
}